package Lab2;

import java.util.ArrayList;
import java.util.Scanner;

public class MyStack extends ArrayList<Object>{

    public int getSize(){
        return size();
    }

    public Object peek(){
        return get(size()-1);
    }

    public Object pop(){
        Object o = peek();
        remove(size()-1);
        return o;
    }

    public void push(Object o){
        add(o);
    }

    public int search(Object o){
        return indexOf(o);
    }

    @Override
    public String toString(){
        StringBuilder sb = new StringBuilder();
        sb.append("MyStack: [");
        for(int i=size()-1; i>0;i--){
            sb.append(get(i));
            sb.append(", ");
        }
        sb.append(get(0));
        sb.append("]");
        return sb.toString();
    }

    //isEmpty(), getSize(), peek(), pop(), push(Object o), search(Object o) and toString().

//    Write a test program that prompts the user to enter five strings and displays them in reverse
//    order.

    public static void main(String[] args){
        MyStack stack = new MyStack();
        Scanner scan = new Scanner(System.in);

        for(int i = 0; i<5; i++){
            stack.push(Integer.parseInt(scan.next()));
        }

        System.out.println(stack);
    }
}
